package com.blogs.tools;



import com.cnblogs.R;
import com.cnblogs.R.color;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class LoadingGif {
	public interface OnReloadListener
	{
		public void onClick();
	}
	private View showView;
	private ViewGroup viewGroup;
	private Button loading_reload;
	
	private LinearLayout loading_ing_load_ll;
	private LinearLayout loading_fail_load_ll;
	private OnReloadListener reloadBtnListener;
	private TextView loading_error_text_tv;
	private TextView text_progressid;
	private DBSharedPreferences sp;
	private Context context;
	public  LoadingGif (Context context,View toBeShowView,ViewGroup viewGroup) {
		this.viewGroup=viewGroup;
		init(context, toBeShowView);
	}
	public LoadingGif (Context context,View toBeShowView,ViewGroup viewGroup,DBSharedPreferences sp)
	{
		this.viewGroup=viewGroup;
		init(context, toBeShowView);
		this.context=context;
		this.sp=sp;
	}
	public void initSkin()
	{
		if(sp!=null)
		{
			if(sp.GetIsDarkState())
			{
				text_progressid.setTextColor(context.getResources().getColor(color.con_butom_night));
				loading_error_text_tv.setTextColor(context.getResources().getColor(color.con_butom_night));
			}
			else
			{
				text_progressid.setTextColor(context.getResources().getColor(color.con_text_light));
				loading_error_text_tv.setTextColor(context.getResources().getColor(color.con_text_light));
			}
		}
	}
	private void init(Context context,View toBeShowView)
	{
		this.showView=toBeShowView;
		this.viewGroup.addView(this.showView,new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		View view=View.inflate(context, R.layout.loading, viewGroup);
		text_progressid=(TextView)view.findViewById(R.id.text_progressid);
		loading_error_text_tv=(TextView)view.findViewById(R.id.loading_error_text_tv);
		loading_reload=(Button)view.findViewById(R.id.loading_reload);
		loading_reload.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(reloadBtnListener!=null)
				{
					reloadBtnListener.onClick();
				}
			}
		});
		loading_ing_load_ll=(LinearLayout)view.findViewById(R.id.loading_ing_load_ll);
		loading_fail_load_ll=(LinearLayout)view.findViewById(R.id.loading_fail_load_ll);
	}
	public void setOnReloadListener(OnReloadListener reloadBtnListener)
	{
		this.reloadBtnListener=reloadBtnListener;
	}
	public void showLoading()
	{
		this.initSkin();
		loading_ing_load_ll.setVisibility(View.VISIBLE);
		showView.setVisibility(View.GONE);
		loading_fail_load_ll.setVisibility(View.GONE);
	}
	public void  showFiale()
	{
		this.initSkin();
		loading_ing_load_ll.setVisibility(View.GONE);
		showView.setVisibility(View.GONE);
		loading_fail_load_ll.setVisibility(View.VISIBLE);
	}
	public void showData()
	{
		loading_ing_load_ll.setVisibility(View.GONE);
		showView.setVisibility(View.VISIBLE);
		loading_fail_load_ll.setVisibility(View.GONE);
	}
}
